package com.frikinet.lifeguard.events;

import java.util.Vector;

import com.frikinet.lifeguard.listeners.AppModelStateListener;


public class EventManager
{
	private boolean modelChanged = false;
	
	private Vector<AppModelStateListener> modelStateListeners = new Vector<AppModelStateListener>();
	
	private Vector<UserSelectedListener> userSelectedListeners = new Vector<UserSelectedListener>();
	private Vector<YearSelectedListener> yearSelectedListeners = new Vector<YearSelectedListener>();
	private Vector<MonthSelectedListener> monthSelectedListeners = new Vector<MonthSelectedListener>();
	private Vector<PostSelectedListener> postSelectedListeners = new Vector<PostSelectedListener>();
	
	public boolean isModelChanged()
	{
		return modelChanged;
	}
	
	public void addModelStateListener(AppModelStateListener listener)
	{
		modelStateListeners.add(listener);
	}
	
	public void addUserSelectedListener(UserSelectedListener listener)
	{
		userSelectedListeners.add(listener);
	}
	
	public void addYearSelectedListener(YearSelectedListener listener)
	{
		yearSelectedListeners.add(listener);
	}
	
	public void addMonthSelectedListener(MonthSelectedListener listener)
	{
		monthSelectedListeners.add(listener);
	}
	
	public void addPostSelectedListener(PostSelectedListener listener)
	{
		postSelectedListeners.add(listener);
	}
	
	public void fireModelChanged()
	{
		modelChanged = true;
		for(AppModelStateListener listener: modelStateListeners)
		{
			listener.modelChanged();
		}
	}
	
	public void fireUserSelected(UserSelectedEvent event)
	{
		for(UserSelectedListener listener: userSelectedListeners)
		{
			listener.userSelected(event);
		}
	}
	
	public void fireYearSelected(YearMonthSelectedEvent event)
	{
		for(YearSelectedListener listener: yearSelectedListeners)
		{
			listener.yearSelected(event);
		}
	}
	
	public void fireMonthSelected(YearMonthSelectedEvent event)
	{
		for(MonthSelectedListener listener: monthSelectedListeners)
		{
			listener.monthSelected(event);
		}
	}
	
	public void firePostSelected(PostSelectedEvent event)
	{
		for(PostSelectedListener listener: postSelectedListeners)
		{
			listener.postSelected(event);
		}
	}
}
